/**
 * @description 注册
 */
//公用样式 
require('../../assets/css/index.less');

//引入weui库
require('../../assets/lib/weui/weui.css');
let weui = require('../../assets/lib/weui/weui.js');
//引入图标
require('../../assets/fonts/iconfont.css');
//当前页面样式
require('./courseTraining.less');
//工具函数 utils
const dom = require('../../utils/dom');
const local = require('../../utils/local.js');
//引入axios封装的文件
let https = require('../../utils/https.js');

//DOM加载事件
dom.reday(function () {
    dom.headerH("courseTraining")
    dom.footerH("circle");
    //获取课程列表
    function getCourseList() {
        https.get('/api/train/courseList', function (res) {
            let { errno, data } = res;
            if (errno == 0) {
                data.map((v, i) => {
                    if (i == 0) {
                        rander('#newCourse', v)
                    }
                })
            }
        })
    }
    getCourseList();

    //渲染数据
    function rander(obj, data) {
        dom.getEle(obj).innerHTML += `<li>
            <img src="${https.BASE_URL + data.imgurl}" alt="" data-id="${data.courseId}">
            <div class="plf5">
                <h2>${data.name}</h2>
                <p>${data.desc}</p>
            </div>
        </li>`
    }
    dom.getEle('#newCourse').addEventListener('click', function (e) {
        if (e.target.nodeName == 'IMG') {
            let id = e.target.dataset['id'];
            location.href = 'introduce.html?id=' + id;
        }
    })
    dom.getEle('#course').addEventListener('click', function (e) {
        if (e.target.nodeName == 'IMG') {
            let id = e.target.dataset['id'];
            location.href = 'introduce.html?id=' + id;
        }
    })
})
// 课程
function getCourseList() {
    https.get('/api/train/courseList', function (res) {
        let { errno, data } = res;
        if (errno == 0) {
            data.map((v, i) => {
                if (i !== 0) {
                    rander('#course', v)
                }
            })
        }
    })
}
getCourseList();

//渲染数据
function rander(obj, data) {
    dom.getEle(obj).innerHTML += `<li>
        <img src="${https.BASE_URL + data.imgurl}" alt="" data-id="${data.courseId}" id="courseimg">
        <div class="plf6">
            <h2>${data.name}</h2>
            <p>${data.desc}</p>
        </div>
    </li>`
}

// document.querySelector('#courseimg').addEventListener('click', function (d) {
//     if (d.target.nodeName == 'IMG') {
//         let id = d.target.dataset['id'];
//         location.href = 'courseDetail.html?id=' + id;
//     }
// })
// dom.getEle("#courseimg").addEventListener("click",function(){
// alert(1211)
// })
